package ${pojoPackageName}.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.luoqiz.utils.MsgJson;
import com.luoqiz.utils.PageTools;

import ${pojoPackageName}.model.${pojoName};
import ${pojoPackageName}.model.${pojoName}Condition;
import ${pojoPackageName}.service.${pojoName}Service;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Controller
@RequestMapping("/${pojoName?uncap_first}")
public class ${pojoName}Controller{

    @Autowired
    private ${pojoName}Service ${pojoName?uncap_first}Service;
    
    @ApiOperation(value = "全数据添加", notes = "对所有字段处理添加记录")
    @RequestMapping(value = "/save${pojoName}", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson save${pojoName}(${pojoName} ${pojoName?uncap_first}) {
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.save${pojoName}(${pojoName?uncap_first}));
            msg.setSuccess(true);
            msg.setMsg("添加记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("添加记录失败！");
        }
        return msg;
    }
    
    @ApiOperation(value = "部分数据添加", notes = "只对不为null的字段处理添加记录")
    @RequestMapping(value = "/save${pojoName}Selective", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson save${pojoName}Selective(${pojoName} ${pojoName?uncap_first}) {
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.save${pojoName}Selective(${pojoName?uncap_first}));
            msg.setSuccess(true);
            msg.setMsg("添加记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("添加记录失败！");
        }
        return msg;
    }
    
    /**
     * 
    * @Title: list${pojoName}Condition      
    * @Description: 根据条件获取多条记录
    * @param ${pojoName}Condition
    * @return MsgJson
    * @throws Exception
     */
    @ApiOperation(value = "获取多条记录", notes = "根据条件获取多条记录")
    @RequestMapping(value = "/list${pojoName}Condition", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson list${pojoName}Condition(${pojoName}Condition ${pojoName?uncap_first}Condition) throws Exception {
        int total = ${pojoName?uncap_first}Service.count${pojoName}Condition(${pojoName?uncap_first}Condition);
        List<${pojoName}> rows = ${pojoName?uncap_first}Service.list${pojoName}Condition(${pojoName?uncap_first}Condition);
        MsgJson msg = new MsgJson();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", total);
		map.put("rows", rows);
		msg.setData(map);
		msg.setStatus(200);
		msg.setSuccess(true);
		return msg;
    }
    /**
     * 
    * @Title: remove${pojoName}ByPrimaryKey     
    * @Description: 根据主键删除一条记录 
    * @param ${javaTablePK}
    * @return MsgJson
    * @throws Exception
     */
    @ApiOperation(value = "删除特定数据", notes = "根据主键删除一条记录")
    @RequestMapping(value = "/remove${pojoName}ByPrimaryKey", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson remove${pojoName}ByPrimaryKey(String ${javaTablePK}) {
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.remove${pojoName}ByPrimaryKey(${javaTablePK}));
            msg.setSuccess(true);
            msg.setMsg("删除记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("删除记录失败！");
        }
        return msg;
    }
    
    /**
     * 
    * @Title: removeList${pojoName}ByPrimaryKey     
    * @Description: 根据主键批量删除记录 
    * @param ${javaTablePK}Array
    * @return MsgJson
    * @throws Exception
     */
    @ApiOperation(value = "批量删除特定数据", notes = "根据主键批量删除记录")
    @RequestMapping(value = "/removeList${pojoName}ByPrimaryKey", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson removeList${pojoName}ByPrimaryKey(String[] ${javaTablePK}Array) throws Exception{
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.removeList${pojoName}ByPrimaryKey(${javaTablePK}Array));
            msg.setSuccess(true);
            msg.setMsg("批量删除记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("批量删除记录失败！");
        }
        return msg;
    }
    
    /**
     * 
    * @Title: update${pojoName}ByPrimaryKey     
    * @Description: 根据主键更新一条记录（所有字段更新）
    * @param ${pojoName}
    * @return MsgJson
    * @throws Exception
     */
    @ApiOperation(value = "全数据更新", notes = "根据主键更新一条记录（所有字段更新）")
    @RequestMapping(value = "/update${pojoName}ByPrimaryKey", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson update${pojoName}ByPrimaryKey(${pojoName} ${pojoName?uncap_first}) throws Exception{
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.update${pojoName}ByPrimaryKey(${pojoName?uncap_first}));
            msg.setSuccess(true);
            msg.setMsg("更新记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("更新记录失败！");
        }
        return msg;
    }
   
    /**
     * 
    * @Title: update${pojoName}ByPrimaryKeySelective 
    * @Description: 根据主键更新一条记录（不为null的字段更新）
    * @param ${pojoName}
    * @return MsgJson
    * @throws Exception
    */
    @ApiOperation(value = "部分数据更新", notes = "根据主键更新一条记录（不为null的字段更新）")
    @RequestMapping(value = "/update${pojoName}ByPrimaryKeySelective", method = RequestMethod.POST)
    @ResponseBody
    public MsgJson update${pojoName}ByPrimaryKeySelective(${pojoName} ${pojoName?uncap_first}) throws Exception{
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.update${pojoName}ByPrimaryKeySelective(${pojoName?uncap_first}));
            msg.setSuccess(true);
            msg.setMsg("更新记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("更新记录失败！");
        }
        return msg;
    }
    
    /**
     * 
    * @Title: get${pojoName}ByPrimaryKey  
    * @Description: 根据主键获取单条记录
    * @param ${pojoName}Condition
    * @return MsgJson 
    * @throws Exception
     */
   @ApiOperation(value = "获取特定记录", notes = "根据主键获取单条记录")
   @RequestMapping(value = "/get${pojoName}ByPrimaryKey", method = RequestMethod.POST)
   @ResponseBody
   public MsgJson get${pojoName}ByPrimaryKey(String ${javaTablePK}) throws Exception{
        MsgJson msg=new MsgJson();
        try {
            msg.setData(${pojoName?uncap_first}Service.get${pojoName}ByPrimaryKey(${javaTablePK}));
            msg.setSuccess(true);
            msg.setMsg("获取记录成功！");
        } catch (Exception e) {
            
            e.printStackTrace();
            msg.setMsg("获取记录失败！");
        }
        return msg;
   }
    
    
    public ${pojoName}Service get${pojoName}Service() {
        return ${pojoName?uncap_first}Service;
    }
    public void set${pojoName}Service(${pojoName}Service ${pojoName?uncap_first}Service) {
        this.${pojoName?uncap_first}Service = ${pojoName?uncap_first}Service;
    }
}